package com.dragon.app.concurrent;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 
 * <p>class: ReentrantLockTest</p>  
 * <p>Description: 测试ReentrantLock</p>  
 * @author SmallDragon
 * @date 2019年5月6日
 *
 */
public class ReentrantLockTest {

	public static void main(String[] args) {
		Source source = new Source();
		
		new Thread(() -> {
			source.get();
		}).start();

		new Thread(() -> {
			source.get();
		}).start();

	}
	
	
	
	
	
	static class Source{
		Lock lock = new ReentrantLock(false);
		
		public void get() {
			lock.lock();
			//lock.lock();
			try {
				System.out.println(Thread.currentThread().getId() + ":get");
				set();
			} finally {
				lock.unlock();
				//lock.unlock();
			}
		}

		public void set() {
			lock.lock();
			try {
				System.out.println(Thread.currentThread().getId() + ":set");
			} finally {
				lock.unlock();
			}
		}
		
		
	}
	

}
